<%@ page import="com.tianmao.model.Product" %>
<%@ page import="java.util.List" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="images/shortcut.png" rel="shortcut icon" type="image/x-icon"/>
        <link rel="stylesheet" href="css/bootstrap.min.css"/>
        <link rel="stylesheet" href="css/style.css"/>
        <title>购物车信息</title>
    </head>
    <body>

        <div class="container">
            <h1 class="text-center text-danger">购物车信息</h1>
            <!--这里给出了购物车中一个产品的显示格式-->
            <%
                List<Product> list = (List<Product>) session.getAttribute("cartList");
                // 购物车列表可能为空
                if(null == list) {
                    out.println("<hr>");
                    out.println("<h1 class='text-center text-warning'>尚未添加任何产品到购物车<h1>");
                    return;
                }
            %>
            <% double sum = 0; %>
            <% for(Product product : list) {%>
            <div class="cartProduct">
                <img src="images/<%= product.getProductId() %>.jpg" width="120" height="120">
                <hr>
                产品名称：<%= product.getProductName() %>
                <br>产品单价：<%= product.getProductPrice() %>
                <br>包装单位：<%= product.getProductUnit() %>
                <br>购买数量：<%= product.getProductQty() %>
                <%
                    double price = product.getProductQty() * product.getProductPrice();
                    sum += price;
                %>
                <br><b class="text-primary">小计金额: <%= price %></b>
            </div>
            <hr>
            <%}%>
            <h3 class="text-danger">总计金额：<%= sum %></h3>
        </div>
    </body>
</html>
